import React, { Suspense } from "react";

import {
  BrowserRouter,
  HashRouter,
  Routes,
  Route,
  Navigate,
} from "react-router-dom";
import Routers from "./Router/RouterConfig";
import { RoutherHome } from "./Router/ulits";
function App() {
  const { mode, routes } = Routers;
  const routerlist=(arr:RoutherHome[])=>{
    return arr.map((item,index)=>{
      return (
        <Route path={item.path} key={index} element={item.to?<Navigate to={item.to}></Navigate>:<item.element></item.element>} >
          {
            item.children&&routerlist(item.children)
          }
        </Route>
      )
    })
  }
  return (
    <Suspense>
      {mode === "history" ? (
        <BrowserRouter>
        <Routes>
          {
            routerlist(routes)
          }
        </Routes>
        </BrowserRouter>
      ) : (
        <HashRouter>
          <Routes>
          {
            routerlist(routes)
          }
        </Routes>
        </HashRouter>
      )}
    </Suspense>
  );
}

export default App;
